package com.itzxx.huazhun.ui.collection.readall

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import com.itzxx.huazhun.data.model.ProbeAllInfo
import com.itzxx.huazhun.data.model.ProbeInfo
import com.itzxx.huazhun.databinding.ActivityReadCollectionAllDataBinding
import com.itzxx.huazhun.ui.collection.read.ReadCollectionDataAdapter
import com.itzxx.library_base_ktx.base.activity.BaseVmDbActivity
import com.itzxx.library_base_ktx.ext.view.addLinearAdapter

class ReadCollectionAllDataActivity :
    BaseVmDbActivity<ReadCollectionAllDataViewModel, ActivityReadCollectionAllDataBinding>() {
    companion object {
        fun startActivity(context: Context, probeAllInfo: ProbeInfo?) {
            val intent = Intent(
                context,
                ReadCollectionAllDataActivity()::class.java
            )
            intent.putExtra("data", probeAllInfo)
            context.startActivity(
                intent
            )
        }
    }

    private lateinit var readCollectionAllDataAdapter: ReadCollectionAllDataAdapter

    override fun initView(savedInstanceState: Bundle?) {
        setSupportActionBar(mDatabind.tbHead)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        intent?.run {
           mViewModel.initProbeInfo(getParcelableExtra<ProbeInfo>("data"))
        }
        readCollectionAllDataAdapter = ReadCollectionAllDataAdapter()
        mDatabind.rvList.addLinearAdapter(readCollectionAllDataAdapter)
    }

    override fun createObserver() {
        mViewModel.run {
            probeInfoObservableField.observe(this@ReadCollectionAllDataActivity){
                val list = it.getList()
                readCollectionAllDataAdapter.submitList(list)
            }

            mDatabind.btReadCheckdata.setOnClickListener {
                checkReadData(readCollectionAllDataAdapter.checkMap)
            }
        }

    }

    override fun databind2ViewModel() {
        super.databind2ViewModel()
        mDatabind.viewmodel = mViewModel
    }

    override fun onSupportNavigateUp(): Boolean {
        finish()
        return true
    }

    override fun isApplyDefaultWaitDialog(): Boolean {
        return true
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    }

    override fun onDestroy() {
        super.onDestroy()
        window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    }
}